<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@include file="/resource/common/taglib.jspf"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${SESSION_COMPANY}</title>
<%@include file="/resource/common/jquery.jspf"%>
<%@include file="/resource/common/commonCss.jspf"%>
<%@include file="/resource/common/kindeditor.jspf"%>
<%@include file="/resource/common/bootstrap.jspf"%>
<%@include file="/resource/common/validate.jspf"%>
<%@include file="/resource/common/showLoading.jspf"%>
<script type="text/javascript" src="${ctxStatic }/plugins/jquery/jquery.ztree/ztreeLayerIframeAjaxPostUtils.js"></script>
<script type="text/javascript" src="${ctxStatic }/plugins/jquery/jquery.ztree/ztreeLayerOpenSelectedUtils.js"></script>
<style type="text/css">
<!--

-->
</style>
<script type="text/javascript">
	//服务器URL地址
	var PATH = "${ctx}";
	//初始在线编辑器
    ShowEditorHtml("#description", "word_count");
	var result = 0;
	var validateForm;
	$(document).ready(function() {
		//数据验证
		validateForm = $("#inputForm").validate({
			rules : {
				name : {
					required : true
				},
				sort : {
					required : true,
					digits:true,
					min : 0
				}
			},
			messages : {
				name : {
					required : "请输入菜单名称"
				},
				sort:{
					required : "排序不能为空同时为数字"
				}
			},
			errorElement : "em",
			errorClass : "validate_error",
			submitHandler: function(form) { //通过之后回调
				//save();
			},
			invalidHandler: function(form, validator) {
				return false;
			}
		});
		setAuthority();
	});
	
	//设置选中的权限
	function setAuthority() {
		var aulist = $("#aulist").val();
		var array = aulist.split(',',-1);
		var html = '';
		var ids = '';
		var checkName = ''
		$.each(array, function(i, item) {
			var items = item.split('###',-1);
			if(items[0]!=''){
				ids +=items[0]+"#";
				checkName +=items[1]+"#";
				if(i%2==0){
					html +='<button type="button" id="authority_'+items[0]+'" class="btn btn-xs btn-info" style="margin-bottom:5px;margin-right:15px;">【'+items[1]+'】&nbsp;</button><span class="btn-danger circle_del" id="authority_span_'+items[0]+'" title="移除" onclick="removeAu('+items[0]+',\''+items[1]+'\')">x</span>';
				}else{
					html +='<button type="button" id="authority_'+items[0]+'" class="btn btn-xs btn-success" style="margin-bottom:5px;margin-right:15px;">【'+items[1]+'】&nbsp;</button><span class="btn-danger circle_del" id="authority_span_'+items[0]+'" title="移除" onclick="removeAu('+items[0]+',\''+items[1]+'\')">x</span>';
				}
			}
		});
		$("#authority-box").html(html);
		if(ids!=''){
			ids = ids.substring(0, ids.length - 1);
			checkName = checkName.substring(0, checkName.length - 1);
			$("#authority").val(ids);
			$("#checkName").val(checkName);
		}
	}
	
	function removeAu(id,name){
		var ids = $("#authority").val();
		var v = $("#checkName").val();
		v = functionUtil.replaceAllValue(functionUtil.replaceAllValue(functionUtil.replaceAllValue(v,name+"#",""),"#"+name,""),name,"");
		ids = functionUtil.replaceAllValue(functionUtil.replaceAllValue(functionUtil.replaceAllValue(ids,id+"#",""),"#"+id,""),id,"");
		$("#authority").val(ids);
		$("#checkName").val(v);
		$("#authority_"+id).remove();
		$("#authority_span_"+id).remove();
	}
</script>
</head>
<body>
	<div id="body-wrapper">
		<div id="main-content">
			<div class="content-box-content">
				<div class="tab-content default-tab" id="tab1">
					<input type="hidden" id="asyncResult" name="asyncResult" value="-1" /> 
					<input type="hidden" id="asyncResultData" name="asyncResultData" value="-1" /> 
					<input type="hidden" id="asyncResultError" name="asyncResultError" value="-1" /> 
					<input type="hidden" id="aulist" name="aulist" value="${entity.aulist }" /> 
					<input type="hidden" id="checkName" name="checkName" />
					<form id="inputForm" action="saveSysModule.do" class="form-horizontal" method="post">
						<div class="row">
							<div class="col-md-6 col-sm-6 col-xs-6" >
								<div class="form-group">
									<label class="col-md-2 col-sm-2 col-xs-2 control-label">菜单名称：<span style="color: red">*</span></label>
									<div class="col-md-10 col-sm-10 col-xs-10">
										<input type="hidden" id="mid" name="mid" value="${entity.mid }" /> 
										<input type="hidden" id="pid" name="pid" value="${entity.pid}" /> 
										<input type="text" class="form-control input-sm" name="name" id="name"  value="${entity.name }" placeholder="菜单名称"/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 col-sm-2 col-xs-2 control-label">标识　码：<span style="color: red">*</span></label>
									<div class="col-md-10 col-sm-10 col-xs-10">
										<input type="text" class="form-control input-sm" name="tag" id="tag"  value="${entity.tag }" placeholder="标识码"/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 col-sm-2 col-xs-2 control-label">排　　序：<span style="color: red">*</span></label>
									<div class="col-md-10 col-sm-10 col-xs-10">
										<input type="text" class="form-control input-sm" name="sort" id="sort"  value="${entity.sort }" placeholder="排序"/>
									</div>
								</div>
							</div>
							<div class="col-md-6 col-sm-6 col-xs-6" >
								<div class="form-group">
									<label class="col-md-2 col-sm-2 col-xs-2 control-label">访问地址：</label>
									<div class="col-md-10 col-sm-10 col-xs-10">
										<input type="text" class="form-control input-sm" name="url" id="url"  value="${entity.url }"  placeholder="访问地址"/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 col-sm-2 col-xs-2 control-label">模块图标：</label>
									<div class="col-md-10 col-sm-10 col-xs-10">
										<input type="text" class="form-control input-sm" name="icon" id="icon"  value="${entity.icon }" placeholder="模块图标" />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">状　　态：<span style="color: red">*</span></label>
									<div class="col-md-10 col-sm-10 col-xs-10">
										<select name="enable" id="enable" class="form-control input-sm">
											<option value="1" <c:if test="${entity.enable=='1'}">selected="selected"</c:if>>启用</option>
											<option value="0" <c:if test="${entity.enable=='0' }">selected="selected"</c:if>>禁用</option>
										</select>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-md-12 col-sm-12 col-xs-12" >
								<div class="form-group">
									<label class="col-md-1 col-sm-1 col-xs-1 control-label">权　　限：<span style="color: red">*</span></label>
									<div class="col-md-11 col-sm-11 col-xs-11">
										<button type="button" class="btn btn-xs btn-danger"  style="cursor: pointer" onclick="ztreeLayerOpenSelectedUtils.openSelectedShowByWH('authority','checkName','authority-box','allotMenuAuthority.do',300,380);" ><i class="fa fa-plus"></i> 权限节点</button>
										<input type="hidden" id="authority" name="authority" />
										<div id="authority-box" style="width: 100%;margin-top: 5px;"></div>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-1 col-sm-1 col-xs-1 control-label">描　　述：</label>
									<div class="col-md-11 col-sm-11 col-xs-11">
										<textarea id="description" name="description" style="width: 100%; height: 150px; visibility: hidden;">${entity.description }</textarea> 您当前输入了 <span class="word_count">0</span> 个文字。（字数统计包含纯文本、IMG、EMBED，不包含换行符，IMG和EMBED算一个文字。）
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</body>

</html>
